﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;

namespace DAO
{
    public class BoPhanRepository
    {
        public List<BoPhanDTO> LayDanhSachBoPhan()
        {
            List<BoPhanDTO> list = new List<BoPhanDTO>();
            try
            {
                QLTVEntities contex = new QLTVEntities();
                var query = from bophan in contex.BO_PHANList
                            select bophan;
                foreach (var bophanEF in query)
                {
                    BoPhanDTO bophanDTO = new BoPhanDTO();
                    bophanDTO.MaBoPhan = bophanEF.MaBoPhan;
                    bophanDTO.TenBoPhan = bophanEF.TenBoPhan;
                    list.Add(bophanDTO);
                }
            }
            catch (System.Exception)
            {
            }
            return list;
        }

        public BoPhanDTO LayThongTinBoPhan(int maBoPhan)
        {
            BoPhanDTO bophanDTO = new BoPhanDTO();
            try
            {
                QLTVEntities context = ContextFactory.GetInstance();
                var query = from bophan in context.BO_PHANList
                            where bophan.MaBoPhan == maBoPhan
                            select bophan;
                BO_PHAN bophanTemp = query.First();
                if (bophanTemp != null)
                {
                    bophanDTO.MaBoPhan = bophanTemp.MaBoPhan;
                    bophanDTO.TenBoPhan = bophanTemp.TenBoPhan;
                    bophanDTO.TenTat = bophanTemp.TenTat;
                }
            }
            catch (System.Exception)
            {

            }
            return bophanDTO;
        }
    }
}
